package com.example.helloword.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.helloword.R;

import java.util.List;

public class BaseTabFragment extends Fragment {
    private List tabViews;
    private List fragments;
    private LinearLayout tabLayout;


    public BaseTabFragment() {
    }


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.base_tab_fragment_layout, null);
        tabLayout = inflate.findViewById(R.id.linearLayout);

        addTab();
        addFragment();

        return inflate;
    }

    public void addTab() {
        tabLayout.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
            tabLayout.getViewTreeObserver().removeOnGlobalLayoutListener((ViewTreeObserver.OnGlobalLayoutListener) this);
            int i = tabLayout.getMeasuredWidth() / tabViews.size();
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            layoutParams.width = i;
            for (int j=0;j<tabViews.size();j++){
                TextView textView = new TextView(getContext());
                textView.setPadding(10,10,10,10);
                textView.setLayoutParams(layoutParams);
                tabLayout.addView(textView);
            }



        });


    }

    public void addFragment() {

    }
}
